local CommonOHOH = _G.CommonOHOH;
local M = CommonOHOH.class.new(script, CommonOHOH.files.BaseComponent());

local CallBackManager = CommonOHOH.load.CallBackManager();

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);
	self.player=self.parent.player


    self.FindAttackTargetEvent=self.parent.player.FindAttackTargetEvent


   local touchPart=self:GetEnterTouchPart()
    CallBackManager:AddRbxConnect(self,touchPart.Touched, function(obj,chPart)
        if self.attacking or not _G.CommonOHOH.load.GeneralTool().IsMeTouchEvent(chPart) then
            return
        end
        self.attacking=true
        self:Enter()
        
	end);

    CallBackManager:AddRbxConnect(self,touchPart.TouchEnded, function(obj,chPart)
        if (not self.attacking) or not _G.CommonOHOH.load.GeneralTool().IsMeTouchEvent(chPart) then
            return
        end
        self.attacking=nil
        self:Leave()
	end);

end;



function M.GetEnterTouchPart(self)
    return  self.parent.main_inst:WaitForChild("Touch")
end


--进入训练区
function M.Enter(self)
    self:CloseTipNotEnoughLevel()
    local unlock,errCode=self.parent:IsUnLock()
    
    if unlock then --是否已经解锁
       self.parent:OpenTrian()

    --    print("---------training_ground----Enter-----------")
       self.player.OnboardingFunnelEvent:Action("training_ground") --统计：进入训练区域

    else
        -- 错误值：1，不是vip，2等级不够,提示
        if errCode==1 then
            _G.ClientOHOH.load.UIManager().ui_list.VipInfoGui:Show()
        elseif errCode==2 then
            _G.GlobalTipGui:Show( _G.LanguageHelper:GetText(888003))
            self:OpenTipNotEnoughLevel()
        end
    end
end


function M.OpenTipNotEnoughLevel(self)
    self.FindeAttackTargetCon=  self.FindAttackTargetEvent:Connect(function(character)
        _G.GlobalTipGui:Show( _G.LanguageHelper:GetText(888003))
  end)

end

function M.CloseTipNotEnoughLevel(self)
    if  self.FindeAttackTargetCon then
        self.FindeAttackTargetCon:Disconnect()
         self.FindeAttackTargetCon=nil
   end
end


--离开训练区
function M.Leave(self)
   self:CloseTipNotEnoughLevel()
    self.parent:CloseTrian()
end

function M.dtor(self)

	M.super.dtor(self);
end


return M